package com.joshua.netdemo.OkHttpDemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;

import com.joshua.androidlib.RemoteService;
import com.joshua.androidlib.RequestParameter;
import com.joshua.androidlib.RequestCallback;
import com.joshua.androidlib.UrlConfigManager;
import com.joshua.netdemo.R;

import java.util.ArrayList;
import java.util.List;

public class OkHttpAty extends AppCompatActivity {
    private static final String API_BASE_URL = "http://192.168.0.1:8080/WebDemo";

    private TextView tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ok_http_aty);

        tv = (TextView) findViewById(R.id.web_content);

        test2();
    }

    public void test2() {
        UrlConfigManager.setResource(R.xml.url);
        List<RequestParameter> params = new ArrayList<>();
        params.add(new RequestParameter("id", "10"));
        RemoteService.getInstance().invoke(this, "sayHello", params, new
                RequestCallback<ZipCode>(ZipCode.class) {
            @Override
            public void onSuccess(ZipCode zipCode) {
                Log.w("joshua", "onSuccess: " + zipCode.getName());
                Log.w("joshua", "onSuccess: " + zipCode.getAreaId());
                Log.w("joshua", "onSuccess: " + zipCode.getParentId());
            }

            @Override
            public void onFailure(int code, String message) {
            }
        });
    }

}
